package org.wsjy.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;

import org.junit.Test;
import org.wsjy.model.TService;

public class TestField {

    @Test
    public void getFields(){
        Field[] fieldArray = TService.class.getDeclaredFields();
        TService service = new TService();
        service.setStId("424fasdfadf");
        service.setDtCreateTime(new Date());
        service.setStFee("123.2");
        for(Field field : fieldArray){
            String fieldName = field.getName();
            System.out.print(fieldName +":");
            try {
                String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1,fieldName.length());
                Method method = TService.class.getDeclaredMethod(methodName);
                System.out.println(method.invoke(service));
            } catch (NoSuchMethodException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
